package cn.tedu.storage.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * @author 郭鲁政
 */
@LocalTCC
public interface StorageTccAction {

    /**
     * 第一阶段方法
     * 避开seata的BUG 订单数据一个一个单独传递,而不用封装的 Order 对象
     *
     * @param businessActionContext 上下文
     * @param productId             商品ID
     * @param count                 商品数量
     * @return
     */
    @TwoPhaseBusinessAction(name = "StorageTccAction", commitMethod = "commit", rollbackMethod = "rollback")
    boolean prepare(BusinessActionContext businessActionContext,

                    @BusinessActionContextParameter(paramName = "productId") Long productId,
                    @BusinessActionContextParameter(paramName = "count") Integer count);

    /**
     * 提交
     *
     * @param businessActionContext 业务操作上下文
     * @return
     */
    boolean commit(BusinessActionContext businessActionContext);

    /**
     * 回滚
     *
     * @param businessActionContext 业务操作上下文
     * @return
     */
    boolean rollback(BusinessActionContext businessActionContext);
}
